'use strict';

module.exports = app => {
    const {DataTypes} = app.Sequelize;
    const Room = app.model.define('room', {
        id: { 
            type: DataTypes.UUID,
            defaultValue: app.Sequelize.UUIDV4,
            primaryKey: true,
            notNull: true,
            unique: true,
            comment: 'ID'
        },
        name:{
            type: DataTypes.STRING(20),
            notNull: true,
            unique: true,
            comment: '房间名称',
            len: [1,18], 
        },
        num: {
            type: DataTypes.STRING(6),
            notNull: true,
            len: [6,6],
            comment: '房间号'
        },
        owners: {
            type: DataTypes.STRING(20),
            notNull: true,
            comment: '房主名字'
        },
        owners_id: {
            type: DataTypes.UUID,
            notNull: true,
            comment: '房主ID'
        },
        game_num: {
            type: DataTypes.INTEGER,
            notNull: true,
            min: 5,
            max: 15,
            comment: '游戏人数'
        },
        person_num: {
            type: DataTypes.INTEGER,
            notNull: true,
            defaultValue:1,
            min: 1,
            max: 15,
            comment: '玩家人数'
        },
        is_start: {
            type: DataTypes.BOOLEAN,
            notNull: true,
            defaultValue:false,
            comment: '是否已经开始游戏'
        },
        is_over: {
            type: DataTypes.BOOLEAN,
            notNull: true,
            defaultValue:false,
            comment: '是否已经结束游戏'
        },
        create_time: {
            type:DataTypes.DATE(6),
            notNull: true,
            defaultValue: app.Sequelize.NOW,
            comment: '创建时间'
        },
        update_time:{
            type:DataTypes.DATE(6),
            notNull: true,
            defaultValue: app.Sequelize.NOW,
            comment: '更新时间'
        },
    },
    {
        timestamps: false
    }
  );
  return Room;
};